package com.laf.manage.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.laf.manage.domain.po.PushMsg;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.laf.common.utils.StringUtils;

import java.time.LocalDateTime;
import java.util.List;

import com.laf.manage.mapper.mp.PushMsgMapper;

import com.laf.manage.service.IPushMsgService;

/**
 * 消息推送记录Service业务层处理
 *
 * @author zian
 * @date 2024-10-30
 */
@Service
public class PushMsgServiceImpl extends ServiceImpl<PushMsgMapper, PushMsg> implements IPushMsgService {

    @Autowired
    private PushMsgMapper pushMsgMapper;

    /**
     * 查询消息推送记录列表
     *
     * @param pushMsg 消息推送记录
     * @return 消息推送记录
     */
    @Override
    public List<PushMsg> selectPushMsgList(PushMsg pushMsg)
    {
        List<PushMsg> pushMsgList = pushMsgMapper.selectList(buildQueryWrapper(pushMsg));
        return pushMsgList;
    }


    private LambdaQueryWrapper<PushMsg> buildQueryWrapper(PushMsg query) {
        LocalDateTime beginTime = query.getBeginTime();
        LocalDateTime endTime = query.getEndTime();
        LambdaQueryWrapper<PushMsg> lqw = Wrappers.lambdaQuery();
        lqw.eq(StringUtils.isNotBlank(query.getCId()), PushMsg::getCId, query.getCId());
        lqw.eq(query.getUserId() != null, PushMsg::getUserId, query.getUserId());
        lqw.between(beginTime != null && endTime!= null, PushMsg::getCreateTime, beginTime, endTime);
        lqw.orderByDesc(PushMsg::getCreateTime);
        return lqw;
    }

}
